home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jlistlib.tcl < prev    next >
Encoding:
Text File  |  1995-02-05  |  2.5 KB  |  79 lines

  1. # jlistlib.tcl - procedures for manipulating lists and paths
  2. # Copyright 1994 by Jay Sekora.  All rights reserved, except 
  3. # that this file may be freely redistributed in whole or in part 
  4. # for non¡profit, noncommercial use.
  5. # these procedures are required by
  6. #     browser.tk
  7. #     edit.tk
  8. #     help.tk
  9. #     more.tk
  10. #     people.tk
  11. #     prefs.tk
  12. # they may be located in the file "~/.tk/jlibrary.tcl" (where they will
  13. # be source'd by those applications on startup), or in the site-wide
  14. # tk library directory, where they will be found (and loaded) by the
  15. # default tk  unknown  procedure.
  16. ######################################################################
  17.  
  18. ###### maybe jlist:listtopath and jlist:pathtolist should be in the
  19. ###### browser rather than in a library (because might want to
  20. ###### override them for special modes).
  21.  
  22. ######################################################################
  23. # jlist:listtopath list - translate a list to a full unix path
  24. ######################################################################
  25.  
  26. proc jlist:listtopath {list} {
  27.   if {"x$list" == "x"} {return "/"}
  28.   set path ""
  29.   foreach element $list {
  30.     append path "/$element"
  31.   }
  32.   return $path
  33. }
  34.  
  35. ######################################################################
  36. # jlist:pathtolist path - translate unix path to full list
  37. #   if path is relative, it has [pwd] prepended
  38. ######################################################################
  39.  
  40. proc jlist:pathtolist {path} {
  41.   if {! [string match "/*" $path]} {
  42.     if [catch {pwd} cwd] {
  43.       j:alert -text "Can't get current directory for relative path `$path'."
  44.     } else {
  45.       set path "$cwd/$path"
  46.     }
  47.   }
  48.   set path [string trimleft $path /]
  49.   return [split $path "/"]
  50. }
  51.  
  52. ######################################################################
  53. # jlist:tail list - return last element of list
  54. ######################################################################
  55.  
  56. proc jlist:tail {list} {
  57.   set last [expr [llength $list] - 1]
  58.   return [lindex $list $last]        ;# returns {} on negative numbers
  59. }
  60.  
  61. ######################################################################
  62. # jlist:ancestor generation list - return generation'th ancestor of list
  63. #   ([jlist:ancestor 0] is list itself; [jlist:ancestor 1] is parent)
  64. ######################################################################
  65.  
  66. proc jlist:ancestor {generation list} {
  67.   if {$generation == 0} {return $list}
  68.   set first [expr [llength $list] - $generation]
  69.   if {$first < 0} {
  70.     return {}
  71.   } else {
  72.     return [lreplace $list $first end]    ;# with nothing
  73.   }
  74. }
  75.  
  76.